﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace UCL.Powersource.Helpers
{
    [DataContract(IsReference=true)]
    public class SelectableConfigurationItem<T> : ConfigurationItem<T>
        where T:ILabel
    {

        private static ILog _Log;
        static ILog Log
        {
            get { return _Log ?? (_Log = LogManager.GetLog(typeof(SelectableConfigurationItem<T>))); }
        }

        public SelectableConfigurationItem(T itemtoconfigure)
            : base(itemtoconfigure)
        { }

        #region IsSelected

        /// <summary>
        /// Field storage for property IsSelected
        /// </summary>
        [DataMember]
        private bool _IsSelected = default(bool);

        /// <summary>
        /// Property IsSelected. TODODOC: Insert appropriate summary here
        /// </summary>
        public bool IsSelected
        {
            get { return _IsSelected; }
            set { 
                if (_IsSelected == value) return; 
                _IsSelected = value;
                Log.DebugMethod("SelectableConfigurationItem {0} changed IsSelected to {1}", this.Label, this._IsSelected);
                IsSelected_RecalculateDependencies(); 
            }
        }

        private void IsSelected_RecalculateDependencies()
        {
            //Recalculate all properties here

            //NotifyOfPropertyChange is usually placed as last statement - first change all dependencies and then fire property change
            NotifyOfPropertyChange(() => IsSelected);
        }

        //private void IsSelected_Recalculate()
        //{
        //    _IsSelected = default(bool);
        //    //Insert your code here

        //    IsSelected_RecalculateDependencies();
        //}

        #endregion

        public override string ToString()
        {
            var itemstr="#NULL";
            if (ItemToConfigure!=null) itemstr=ItemToConfigure.GetType().Name;
            return string.Format("SelectableConfigurationItem [{0} : {1}]", Label, itemstr);
        }
	
    }
}
